


//
//  WellCome.swift
//  mywei
//
//  Created by myd on 15/12/17.
//  Copyright © 2015年 myd1. All rights reserved.
//

import UIKit
import SDWebImage
class WellCome: UIViewController {
  var imagelay = NSLayoutConstraint()
    override func loadView() {
        super.loadView()
        image.translatesAutoresizingMaskIntoConstraints=false
        backimage.translatesAutoresizingMaskIntoConstraints=false
        lab.translatesAutoresizingMaskIntoConstraints=false
        self.view.addSubview(backimage)
        self.view.addSubview(image)
        self.view.addSubview(lab)
        self.view.addConstraint(NSLayoutConstraint(item: backimage, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: backimage, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: backimage, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: backimage, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Trailing, multiplier: 1, constant: 0))
        
        imagelay =  (NSLayoutConstraint(item: image, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        self.view.addConstraint(imagelay)
        
        self.view.addConstraint(NSLayoutConstraint(item: image, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: image, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0, constant: 85))
        self.view.addConstraint(NSLayoutConstraint(item: image, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0, constant: 85))
//
        self.view.addConstraint(NSLayoutConstraint(item: lab, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: image, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 16))
        self.view.addConstraint(NSLayoutConstraint(item: lab, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
       
        
    }
    

    
    override func viewDidLoad() {
        super.viewDidLoad()
       setuserimage()
        setnow()
    }
    func setnow()
    {
      
    let users = user1.loadtoken()!
        users.loaduserinfo { (error1) -> () in
            self.lab.text = "欢迎归来" + users.screen_name! as String
            self.image.sd_setImageWithURL(NSURL(string: (users.avatar_large)!))
        }
        
        
    
    }
    func setuserimage()
    {
   let users = user1.loadtoken()
        if users? . avatar_large != nil
        {
       image.sd_setImageWithURL(NSURL(string: (users?.avatar_large)!))
            lab.text = "欢迎归来" + users!.screen_name!
        }
        
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
         imagelay.constant = -500
        
        UIView .animateWithDuration(2, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 3, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
               
                UIView.animateWithDuration(3, animations: { () -> Void in
                   self.lab.alpha=1
                    }, completion: { (_) -> Void in
                        let win = UIApplication.sharedApplication().keyWindow
                        win?.rootViewController = MainTabBarController()
                })
//                UIView .animateWithDuration(3, animations: { () -> Void in
//                    self.lab.alpha=1
//                })
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    lazy var image : UIImageView = {
        let ima =  UIImageView(image: UIImage(named: "avatar"))
        ima.layer.cornerRadius = 42.5
        ima.layer.masksToBounds=true
        return ima
    }()
    lazy var lab : UILabel = {
   let ll = UILabel()
        ll.text="欢迎归来"
        ll.alpha=0
        return ll
    }()
    lazy var  backimage = UIImageView(image: UIImage(named:"Brand Assets"))
  
}
